const moment = require('moment'),
      stringify = require('../utils/json').stringify,
      saveLog = require('../utils/fileSystem').saveLog;

const logger = (req, res, next) => {
    const logMessage = `\n>>> [${moment().format('MMMM DD YYYY @ HH:mm:ss Z')}] NEW ${req.method} REQUEST:\nURL: ${req.url}\nHEADERS:${stringify(req.headers)}\nPARAMS:${stringify(req.params)}\nBODY:${stringify(req.body)}`;

    console.log(logMessage);
    saveLog(logMessage);

    next();
};

module.exports = logger;
